package com.jinbo.footmessageworker.order;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.jinbo.footmessageworker.BaseActivity;
import com.jinbo.footmessageworker.NavigationActivity;
import com.jinbo.footmessageworker.R;
import com.jinbo.footmessageworker.httpbean.OrderBean;
import com.jinbo.footmessageworker.httpretrofit.HttpProtocolFactory;
import com.jinbo.footmessageworker.view.TitleBarView;

import de.hdodenhof.circleimageview.CircleImageView;


public class HistoryOrderDetailActivity extends BaseActivity implements View.OnClickListener {

   // private static final int REQUEST_COMMENT = 100;
    private static String ORDER_INTENT = "order_bean";

    public static void launch(Activity activity, OrderBean orderBean) {
        Intent intent = new Intent(activity, HistoryOrderDetailActivity.class);
        Bundle bundle = new Bundle();
        bundle.putSerializable(ORDER_INTENT, orderBean);
        intent.putExtras(bundle);
        activity.startActivity(intent);
    }
   // ImageView head;
    TextView mDateTV, mWeekTV, mTimeTv, mProjectsTv, mTotalPriceTv;//, mNameTv;
    TextView mContactNameTv, mContactPhoneTv, mContactAddressTv, mContactSexTv;
    TextView mStateTv, mDoTimeTv;
    View comment_reason_ll, have_reason_ll, have_comment_ll, not_comment_ll;//, server_inf_ll;
    TextView reason_tv, comment_tv;
    RatingBar star_rt;
   // Button go_comment_bt;
    OrderBean bean;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_histroy_order_detail);
        TitleBarView titleBarView = (TitleBarView) findViewById(R.id.titleBar);
        titleBarView.setCenterTitle("订单详情");
        titleBarView.setLeftBackButtonIsVisibler(true);
        titleBarView.setListener(TitleBarView.TitleBarEnum.ll_leftBackImageLayout, this);
        //server_inf_ll = findViewById(R.id.server_inf);
        //server_inf_ll.setOnClickListener(this);
        comment_reason_ll = findViewById(R.id.comment_reason);
        have_reason_ll = findViewById(R.id.have_reason);
        have_comment_ll = findViewById(R.id.have_comment);
        not_comment_ll = findViewById(R.id.not_comment);
        comment_tv = (TextView) findViewById(R.id.comment);
        star_rt = (RatingBar) findViewById(R.id.star);
       // go_comment_bt = (Button) findViewById(R.id.go_comment);
        //go_comment_bt.setOnClickListener(this);

        reason_tv = (TextView) findViewById(R.id.reason);
        mDoTimeTv = (TextView) findViewById(R.id.do_time);
        mStateTv = (TextView) findViewById(R.id.state);

        //head = (ImageView) findViewById(R.id.head);
        mDateTV = (TextView) findViewById(R.id.date);
        mWeekTV = (TextView) findViewById(R.id.week);
        mTimeTv = (TextView) findViewById(R.id.time);
        mProjectsTv = (TextView) findViewById(R.id.content);
        mTotalPriceTv = (TextView) findViewById(R.id.total_price);
       // mNameTv = (TextView) findViewById(R.id.name);

        Intent intent = this.getIntent();
        bean = (OrderBean) intent.getSerializableExtra(ORDER_INTENT);

        mDoTimeTv.setText(bean.do_time);

        switch (bean.kind) {
      /*      case 1:
                mStateTv.setText("已接收");
                break;*/
            case 2:
                mStateTv.setText("已拒绝");
                comment_reason_ll.setVisibility(View.VISIBLE);
                have_reason_ll.setVisibility(View.VISIBLE);
                reason_tv.setText(bean.reason);
                break;
            case 3:
                mStateTv.setText("已完成");
                break;
            case 4:
                mStateTv.setText("已撤销");
                comment_reason_ll.setVisibility(View.VISIBLE);
                have_reason_ll.setVisibility(View.VISIBLE);
                reason_tv.setText(bean.reason);
                break;

        }
        if (bean.kind == 3) {
            comment_reason_ll.setVisibility(View.VISIBLE);
            if (TextUtils.isEmpty(bean.comment)) {
                not_comment_ll.setVisibility(View.VISIBLE);
            } else {
                have_comment_ll.setVisibility(View.VISIBLE);
                comment_tv.setText(bean.comment);
                star_rt.setRating((float)bean.star);
            }


        }
        mDateTV.setText(bean.date);
        mWeekTV.setText(bean.week);
        mTimeTv.setText(bean.begin_time + "-" + bean.end_time);
        mProjectsTv.setText(bean.content);//getProjectNames(bean.worker.projects));
        mTotalPriceTv.setText(bean.total_price + "元");//getPrice(bean.worker.projects) + "");
  /*      Glide.with(this)
                .load(HttpProtocolFactory.HOST_URL_USER + bean.worker.head)
                .placeholder(R.drawable.head_small)
                .into(head);
        mNameTv.setText(bean.worker.name)*/;


        mContactNameTv = (TextView) findViewById(R.id.contact_name);
        mContactPhoneTv = (TextView) findViewById(R.id.contact_phone);
        mContactAddressTv = (TextView) findViewById(R.id.contact_address);
        mContactSexTv = (TextView) findViewById(R.id.contact_sex);


        mContactNameTv.setText(bean.contact_name);
        mContactPhoneTv.setText(bean.contact_phone);
        mContactAddressTv.setText(bean.contact_address);
        mContactSexTv.setText(bean.contact_sex);


    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.left_back_layout:
                finish();
                break;
        }
    }



}

